﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CPPEI.Coolzon.Designer.Views
{
    [ValueConversion(typeof(NodeType), typeof(string))]
    public class NodeTypeToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string ret;
            NodeType nodeType = (NodeType)value;
            switch (nodeType)
            {
                case NodeType.Solution:
                    ret = "方案";
                    break;
                case NodeType.Scene:
                    ret = "场景";
                    break;
                case NodeType.Folder:
                    ret = "文件夹";
                    break;
                case NodeType.Template:
                    ret = "模板";
                    break;
                case NodeType.Resource:
                default:
                    ret = "资源";
                    break;
            }

            return ret;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            NodeType nodeType = default(NodeType);
            string str = System.Convert.ToString(value);
            if (string.IsNullOrWhiteSpace(str))
            {
                return nodeType;
            }
            if (string.Equals(str, "方案"))
            {
                nodeType = NodeType.Solution;
            }
            else if (string.Equals(str, "场景"))
            {
                nodeType = NodeType.Scene;
            }
            else if (string.Equals(str, "文件夹"))
            {
                nodeType = NodeType.Folder;
            }
            else if (string.Equals(str, "模板"))
            {
                nodeType = NodeType.Template;
            }
            else
            {
                nodeType = NodeType.Resource;
            }
            return nodeType;
        }
    }
}
